/*
 * UI.c
 *
 *  Created on: 2025年7月6日
 *      Author: 黄少杰
 */

#include "UI.h"

int ui_page = 0;
int page_mode = 0;
uint8_t iii = 0;
int Tem_Flag = 0;
void UI_Show()
{
    if(page_mode == 0)
    {
        if(key == 2)
        {
            if(++ui_page >= 2)
                ui_page = 0;
            key = 0;
        }


        for(int i=0;i<=2;i+=1)
        {
            if(i==ui_page)
            {
                OLED_ShowString(15,i*16,">",OLED_8X16);
                OLED_ShowString(100,i*16,"<",OLED_8X16);
            }
            else
            {
                OLED_ShowString(15,i*16," ",OLED_8X16);
                OLED_ShowString(100,i*16," ",OLED_8X16);
            }
        }


//        OLED_ShowNum(100,16*1,ui_page,3,OLED_8X16);
//        OLED_ShowNum(100,16*2,key,3,OLED_8X16);
        OLED_ShowString(30,0*16,"体温测量",OLED_8X16);
        OLED_ShowString(30,1*16,"环境温度",OLED_8X16);
        OLED_Update();

        GREEN();

    }

    if(key == 3)
    {
        if(ui_page == 0 && page_mode == 0)
        {
            page_mode = 1;
            OLED_Clear();
            OLED_Update();
        }

        if(ui_page == 1 && page_mode == 0)
        {
            page_mode = 2;
            OLED_Clear();
            OLED_Update();
        }
        key = 0;
    }



    if(page_mode == 1)
    {

        OLED_ShowString(30,0*16,"测温进度",OLED_8X16);
        OLED_DrawRectangle(10,1*16 , 100, 16, OLED_UNFILLED);
        OLED_DrawRectangle(10,1*16 , iii, 16, OLED_FILLED);
        OLED_ShowNum(50,16*2,iii,3,OLED_8X16);OLED_ShowChar(75,16*2,'%',OLED_8X16);
        OLED_ShowString(0,3*16,"您的体温:",OLED_8X16);OLED_ShowFloatNum(80,16*3,f_t,2,2,OLED_8X16);

//        OLED_ShowString(70,0*16,"你好",OLED_8X16);
//        OLED_ShowString(70,1*16,"你好",OLED_6X8);
        //R_BSP_SoftwareDelay(300,BSP_DELAY_UNITS_MILLISECONDS);
        OLED_Update();
        if(key == 2)
        {
            Tem_Flag = 1;
            key = 0;
        }

        if(Tem_Flag == 1 && f_flag == 0)
        {
            xuan();
        }

        if(f_flag == 2)
        {
            if(f_t<=35 && f_t>=30)
                GREEN();
            else if(f_t < 30)
                bin();
            else
                RED();

        }
       // R_BSP_SoftwareDelay(300,BSP_DELAY_UNITS_MILLISECONDS);

        if(key == 4)
        {
            page_mode = 0;
            OLED_Clear();
            OLED_Update();
            key = 0;
        }
    }

    if(page_mode == 2)
    {

        xuan_G();
        OLED_ClearArea(0,0,120,16);
        OLED_ClearArea(0,17,50,50);
        OLED_DrawRectangle(0,0 , Temperature1*3,16, OLED_FILLED);
        OLED_ShowFloatNum(80,16*3,Temperature1,2,2,OLED_8X16);

        if(Temperature1<=35 && Temperature1>=30)
            OLED_ShowImage(0, 17, 50, 50, cool);
        else if(Temperature1 < 30)
            OLED_ShowImage(0, 17, 50, 50, cold);
        else
            OLED_ShowImage(0, 17, 50, 50, hot);


        OLED_Update();
        if(key == 4)
        {
            page_mode = 0;
            OLED_Clear();
            OLED_Update();
            key = 0;
        }
    }
}

